enum (parameter type)

Enumerations are specified with type="enum" in the parameter definition and the possible values are specified as a list of strings, values={...}:

    {name="Color", type="enum", values={"Red", "Green", "Blue"}, default="Red"}

An enum parameter will have a single value from the list of values at a time. The parameter choice is presented as a drop down menu:

../../../_images/ui-enum-drop-down.png

The displayed text for the values can be controlled in language resource files files, by specifying translations for the keys of the enum values (“Red”, “Green” and “Blue” in the example).

The current value of an enum-parameter is accessed via self.parameters in execute, which provides a string of one of the the defined values:

  local color = self.parameters.Color
  if color == "Red" then
    print("Red color is selected.")
  end

Enumeration with result references

An enumeration can include result references in its values. This allows specifying named alternatives other than the “None” option of ResultReference, and having specific behavior for the non-reference entries:

    {name='MyEnumReference',
     type="enum",
     values={"TopLeft", -- regular enum value
             "BottomRight", -- regular enum value
             Tool.reference("Point")}, -- result reference
     default="TopLeft"}

The drop-down in this case includes the regular values and a list of all results of the referenced types from the tools in the configuration:

../../../_images/ui-parameter-enum-reference.png

The current value of an enum parameter with references should be compared with the statically defined enum values in execute:

  • If the value matches a statically defined value, that case should be handled as appropriate.

  • If the value doesn’t match any of the statically defined values, a referenced item has been selected and the result reference can be passed to input:getResult.

  local referencedPoint
  if self.parameters.MyEnumReference == "TopLeft" then
    referencedPoint = Point.create(0, 0)
  elseif self.parameters.MyEnumReference == "BottomRight" then
    referencedPoint = Point.create(640, 480)
  else
    -- Retrieve referenced point
    referencedPoint = input:getResult(self.parameters.MyEnumReference)
  end